//
// Created by tang on 2022/1/11.
//

#ifndef DIARYTOOL_REDMINE_APIS_HPP
#define DIARYTOOL_REDMINE_APIS_HPP

#include <list>
#include "json/json.hpp"

namespace RedMine {
    namespace Response {

        // 获取Redmine活动列表
        struct RedMineTimeEntryActivity {
            int id;
            std::string name;

            NLOHMANN_DEFINE_TYPE_INTRUSIVE(RedMineTimeEntryActivity, id, name)
        };
        struct RedMineActivityListResponse {
            std::vector<RedMineTimeEntryActivity> time_entry_activities;

            NLOHMANN_DEFINE_TYPE_INTRUSIVE(RedMineActivityListResponse, time_entry_activities)
        };

        // 搜索RedMine问题
        struct RedMineIssue {
            struct Project {
                int         id;
                std::string name;

                NLOHMANN_DEFINE_TYPE_INTRUSIVE(Project, id, name)
            };

            struct Status {
                int         id;
                std::string name;

                NLOHMANN_DEFINE_TYPE_INTRUSIVE(Status, id, name)
            };

            struct AssignedTo {
                int         id;
                std::string name;

                NLOHMANN_DEFINE_TYPE_INTRUSIVE(AssignedTo, id, name)
            };

            int id;
            Project project;
            Status status;
            AssignedTo assigned_to;
            std::string subject;
            std::string created_on;

            NLOHMANN_DEFINE_TYPE_INTRUSIVE(RedMineIssue, id, project, status, assigned_to, subject, created_on)
        };

        struct RedMineIssueSearchResponse {
            int total_count;
            std::vector<RedMineIssue> issues;

            NLOHMANN_DEFINE_TYPE_INTRUSIVE(RedMineIssueSearchResponse, total_count, issues)
        };

        // 账号信息
        struct UserInfo
        {
            int id;
            std::string login;
            std::string firstname;
            std::string lastname;
            std::string mail;

            NLOHMANN_DEFINE_TYPE_INTRUSIVE(UserInfo, id, login, firstname, lastname, mail)
        };

        // 项目信息
        struct ProjectInfo {
            int         id;
            std::string name;
            std::string identifier;
            std::string description;
            int         status;

            NLOHMANN_DEFINE_TYPE_INTRUSIVE(ProjectInfo, id, name, identifier, description, status)
        };
    }

    std::vector<Response::RedMineTimeEntryActivity> GetRedMineActivities();

    enum SearchFilterType
    {
        SFT_SUBJECT,        // 根据问题标题模糊匹配搜索
        SFT_ISSUE_ID,       // 根据问题编号搜索
        SFT_CNT,            // 无效
    };

    std::vector<Response::RedMineIssue> SearchRedMineIssue(int search_type, const std::string& keyword, bool only_me, bool only_open, int page_size, int page, int* total);

    Response::UserInfo GetCurrentUserInfo();

    Response::ProjectInfo GetIssueProjectInfo(int issue_id);

    bool CreateTimeEntry(int issue_id, const std::string& date, double hours, int activity, const std::string& comment);

    std::string GetIssueProjectDesc(int issue_id);
}

#endif //DIARYTOOL_REDMINE_APIS_HPP
